#include "qgstest.h"
#include "qgspointcloudlayer.h"
#include "qgspointcloudlayerexporter.h"
#include "qgsproviderregistry.h"

// add necessary includes here

class TestLasCrsTransform : public QObject
{
	Q_OBJECT

public:
	TestLasCrsTransform();
	~TestLasCrsTransform();

private slots:
	void initTestCase();
	void cleanupTestCase();
	void validLayer();
	void transformLas();

private:

	QgsPointCloudLayer* mLayer;
};

TestLasCrsTransform::TestLasCrsTransform() {}

TestLasCrsTransform::~TestLasCrsTransform() {}

void TestLasCrsTransform::initTestCase() {
	// init QGIS's paths - true means that all path will be inited from prefix
	QgsApplication::init();
	QgsApplication::initQgis();
	QgsApplication::registerOgrDrivers();
}

void TestLasCrsTransform::cleanupTestCase() {}

void TestLasCrsTransform::validLayer() {
	const QString dataDir(TEST_DATA_DIR); //defined in CmakeLists.txt
	QgsProviderRegistry::instance()->providerMetadata(QStringLiteral("pdal"));

	mLayer = new QgsPointCloudLayer(dataDir + QStringLiteral("/point_clouds/las/cloud.las"), QStringLiteral("layer"), QStringLiteral("pdal"));
	QVERIFY(mLayer->isValid());
}

void TestLasCrsTransform::transformLas() {
	const QString file = "cloud_write.las";
	QgsPointCloudLayerExporter exp(mLayer);
	exp.setFormat(QgsPointCloudLayerExporter::ExportFormat::Las);
	exp.setFileName(file);
	exp.setCrs(QgsCoordinateReferenceSystem(QStringLiteral("EPSG:2154")));
	exp.doExport();
}

QTEST_MAIN(TestLasCrsTransform)

#include "tst_testlascrstransform.moc"
